﻿//-----------------------------------------------------------------------
// <copyright file="PivotTableCellNumberType.cs" company="Forebrain Technology, LLC">
//
// Copyright (c) Forebrain Technology, LLC. All rights reserved.
// 
// This source code is released under the Microsoft Public License (Ms-PL).
//
// </copyright>
//-----------------------------------------------------------------------
namespace PivotCollectionTools.Data
{
    using System;
    using System.Globalization;

    /// <summary>
    /// A Number Type cell.
    /// </summary>
    [Serializable]
    public class PivotTableCellNumberType : PivotTableCell, IColumnDataType
    {
        /// <summary>
        /// The string storage for the value of the Number.
        /// </summary>
        private string textValue;

        /// <summary>
        /// Initializes a new instance of the <see cref="PivotTableCellNumberType"/> class.
        /// </summary>
        /// <param name="column">The column to copy from.</param>
        public PivotTableCellNumberType(PivotTableColumn column)
            : base(column)
        {
        }

        /// <summary>
        /// Gets or sets the number.
        /// </summary>
        /// <value>The number of the pivot table cell number type.</value>
        public decimal Number { get; set; }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value>The value.</value>
        public override string Value
        {
            get 
            {
                return this.textValue;
            }

            set
            {
                this.textValue = value;
                decimal tempValue = 0.0m;
                if (decimal.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out tempValue))
                {
                    this.Number = tempValue;
                }
            }
        }

        /// <summary>
        /// Gets the type of the data.
        /// </summary>
        /// <value>The type of the data.</value>
        public override PivotTableCellType DataType
        {
            get { return PivotTableCellType.Text; }
        }
    }
}
